import axios from "axios";
import cookie from "js-cookie"

const instance = axios.create({
  baseURL: 'http://localhost:3000',
  timeout: 1000,
  headers: {
    'X-Custom-Header': 'foobar'
  },
  withCredentials: true,
})

// 请求拦截
instance.interceptors.request.use(
  config => {
    const token = cookie.get('token');
    config.headers.authorization = token;
    return config;
  },
  err => Promise.reject()
)

// 4. 导出
export default instance
